package com.zpark.se.thread;

/**
 * 模拟购票系统
 */
public class Demo10 {

    public static void main(String[] args) throws InterruptedException {
        // 创建线程对象
        for (int i = 0; i < 15; i++) {
            // 创建线程
            Thread t1 = new Thread(new ThreadDemo());
            // 启动线程
            t1.start();
        }
    }
}

class ThreadDemo implements Runnable {

    private volatile static int num = 10;

    @Override
    public void run() {
        if (num == 0) {
            System.out.println("票已经卖完了");
            return;
        }
        try {
            // 当前线程休眠100毫秒
            Thread.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        num --;
        System.out.println("余票：" + num);
    }
}
